package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import one.stand.aop.AdminController;
import one.stand.entity.excel.BusinessExcelEntity;
import one.stand.entity.excel.CustomerExcelEntity;
import one.stand.enums.ResultEnum;
import one.stand.model.ResultModel;
import one.stand.request.BusinessCardRequest;
import one.stand.request.CompanyRequest;
import one.stand.request.CompanyServiceRequest;
import one.stand.response.BusinessCardResponse;
import one.stand.response.CompanyResponse;
import one.stand.util.ExcelUtil;
import one.stand.util.ExportDataDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author: ZRH
 * @CreateDate: 2019/4/17 9:45
 */
@RestController
@RequestMapping("adminApi/businessCard")
@Api(description = "用户管理",tags="用户管理")
@Slf4j
public class BusinessCardController extends BaseController {

    @ApiOperation(value = "查询用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userType", value = "null为所有   1普通用户  2企业所属人", paramType = "Integer"),
            @ApiImplicitParam(name = "name", value = "条件查询", paramType = "String"),
    })
    @PostMapping("selectCustomerList")
    public ResultModel<Map<String, Object>> selectCustomerList(BusinessCardRequest request) {

        return adminFegin.selectCustomerList(request);
    }

    @ApiOperation(value = "导出用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userType", value = "null为所有  1普通用户  2企业所属人", paramType = "Integer"),
            @ApiImplicitParam(name = "name", value = "条件查询", paramType = "String"),
    })
    @PostMapping("selectCustomerListExport")
    @AdminController(tourist = true)
    public void selectCustomerListExport(BusinessCardRequest request, HttpServletResponse response) {
        ResultModel<ExportDataDTO<BusinessExcelEntity>> resultModel= adminFegin.selectCustomerListExport(request);
        if(resultModel.getCode().equals(ResultEnum.SUCCESS.getCode())){
            ExportDataDTO file=resultModel.getData();
            try{
                ExcelUtil.exportExcel(file, BusinessExcelEntity.class,response);
            }catch (Exception e){
                log.error("导出用户列表[异常]", e);
            }
        }
    }

    @ApiOperation(value = "查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "成员id", required = true, paramType = "Integer"),
    })
    @PostMapping("getCustomerInfo")
    public ResultModel<BusinessCardResponse> getCustomerInfo(BusinessCardRequest request) {
        return adminFegin.getCustomerInfo(request);
    }

    @ApiOperation(value = "禁用用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cardId", value = "公司id", required = true, paramType = "Integer"),
    })
    @PostMapping("stopCustomer")
    @AdminController(tourist = true)
    public ResultModel<Boolean> stopCustomer(BusinessCardRequest request) {
        return adminFegin.stopCustomer(request);
    }
}
